<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('选择代理商')" />
</head>
<body class="gray-bg">
<div class="col-sm-12 search-collapse">
    <form id="formId">
        <div class="select-list">
            <ul>
                <li>
                    服务商编号：
                    <input type="text" name="agentNum" id="agentNum" />
                </li>
                <li>
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()">
                        <i class="fa fa-search"></i>&nbsp;搜索
                    </a>
                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()">
                        <i class="fa fa-refresh"></i>&nbsp;重置
                    </a>
                </li>
            </ul>
        </div>
    </form>
</div>


<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>

<script th:inline="javascript">
    $(function () {
        var agent_status = [[${@dict.getType('agent_status')}]] || [];
        var options = {
            url: ctx + "agentInfo/agentInfo/list3",
            clickToSelect: true,
            // queryParams: function (params) {
            //     // 初始化传参
            //     return {
            //         ...params,
            //         agentStatus: '0'  // 默认查询 agentStatus = 0
            //     };
            // },
            columns: [
                {radio: true},
                {
                    field: 'agentNum',
                    title: '服务商编号'
                },
                {
                    field: 'agentName',
                    title: '服务商名称'
                },
                {
                    field: 'commissary',
                    title: '法人姓名'
                },
                {
                    field: 'showIdentitynum',
                    title: '身份证',
                    formatter: function (value) {
                        return $.table.tooltip(value, 5);
                    }
                },
                {
                    field: 'linkPhone',
                    title: '联系电话'
                },
                {
                    field: 'agentStatus',
                    title: '状态',
                    formatter: function (value) {
                        return $.table.selectDictLabel(agent_status, value);
                    }
                }
            ]
        };
        $.table.init(options);
    });

    // 提交选择
    function submitHandler() {
        var agentNum = $.table.selectColumns("agentNum");
        var agentName = $.table.selectColumns("agentName");

        if (agentNum.length === 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }

        $.modal.close();
        //  根据 obj 传值给不同字段（如有多个用途）
        parent.$("#agentName").val(agentName);
        parent.$("#agentId").val(agentNum);
        // 手动触发 input 和 blur 事件，触发父页面的监听逻辑
        parent.$("#agentName").trigger("input").trigger("blur");
    }
</script>
</body>
</html>
